#include <cstdio>
#include <cstring>

#define MAX_SIZE 10000

int max(int a, int b) {
	return (a > b) ? a : b;
}

void lcs( char *X, char *Y, int m, int n ) { 
	int L[m+1][n+1]; 
  
    for (int i = 0; i <= m; i++) { 
    	for (int j = 0; j <= n; j++) { 
       		if (i == 0 || j == 0) 
         		L[i][j] = 0; 
       		else if (X[i-1] == Y[j-1]) 
         		L[i][j] = L[i-1][j-1] + 1; 
       		else
         		L[i][j] = max(L[i-1][j], L[i][j-1]); 
     	} 
   	} 
  
   printf("%d", L[m][n]);
} 

int main() {
	char x[MAX_SIZE], y[MAX_SIZE];
	scanf("%s", x);
	scanf("%s", y);

	int m = strlen(x);
	int n = strlen(y);

	lcs(x, y, m, n);

	return 0;
}